**Replication file for the paper "Ethnicity or Policy? The Conditioning of Intergroup Trust in the Context of Ethnic Conflict" by Carlin et al. in Political Psychology***

use "PP replication data.dta", clear


***dropping the Mapuche and Mapuche first identifiers (n=29)
drop if P17==2 | P17==4

***testing and generating the mapuche identification scale
		pca P2_1 P2_2 P2_3 P2_4
		alpha P2_1 P2_2 P2_3 P2_4
		alpha P2_1 P2_2 P2_3 P2_4, gen(mapuche_id)
		gen mapuche_id_dummy=1 if mapuche_id>2.5 & mapuche_id~=.
		replace mapuche_id_dummy=0 if mapuche_id<2.6 & mapuche_id~=.
		tab mapuche_id_dummy
		
alpha P19_1 P19_2 P19_3 P19_4, gen(nat_pride)
***
alpha P29_1 P29_2 P29_3 P29_4 P29_5 P29_6, gen(author_personality)

***UNIVARIATE DESCRIPTIVES
		tab1 SEXO REG P31_1, nol
		
		recode P31_1 (88 99=.)
		tab P31_1

*** Left-rigth identification		
		recode P26_1 11=.
		gen ideology_3cat= P26_1

		recode ideology_3cat 2=1 3=1 4=2 5=2 6=2 7=3 8=3 9=3 
		tab P26_1 ideology_3cat

		gen ideology_right_dummy=P26_1
		recode ideology_right_dummy 1=0 2=0 3=0 4=0 5=0 6=1 7=1 8=1 9=1
		*recode groups 2=. 3=2 4=2 5=2 6=2
		
		foreach z of varlist  P21_1 P21_2 P22_1 P22_2 P22_3 {
		*ttest `z', by (groups)
		ttest `z', by (ideology_right_dummy)
		}
		
	
** Wide to Long dataBase
		reshape long Juego_ ,i(numericalId) j(game)
		gen treatment_mapuche=1 if game>2
		replace treatment_mapuche=0 if game<3
		gen treatment_tax=1 if game==1
		replace treatment_tax=1 if game==3
		replace treatment_tax=0 if game==2
		replace treatment_tax=0 if game==4
		rename Juego_ Juego

		pca P19_1 P19_2 P19_3 P19_4

		pca P29_1 P29_2 P29_3 P29_4 P29_5 P29_6
		alpha P29_1 P29_2 P29_3 P29_4 P29_5 P29_6,

		label variable treatment_tax "Tax Treatment"
		label variable treatment_mapuche "Identity Treatment"
		label variable mapuche_id "Mapuche identity scale"
		label variable P3_1 "Trustor Support for pro-mapuche redistribution policies"
		label variable P26_1 "Left-rigth scale"
		label variable SEXO "Gender"
		label variable EDAD "Age"
		label variable Juego "Interpersonal trust - tickets"

		xtset numericalId
		gen female=SEXO
		recode female 1=0 2=1

		
		*************************************************
		*********** MODELS PAPER 1***********************
		*************************************************
		
		***TREATMENT EFFECTS
		** Model I 

		xtreg Juego treatment_tax treatment_mapuche , fe


		xtreg Juego i.treatment_tax##i.treatment_mapuche , fe
	
		***Anova version test for the ATE***
		
		 anova Juego treatment_tax##treatment_mapuche numericalId,  repeated(treatment_mapuche treatment_tax)
			
		
		**MODERATION of Trustor support pro-mapcuhe redistribution
		** Propensity score matching
		** Model III
		** Figure
		
		lab def trustortax2 1"Low level of support" 2"A litle" 3"Some" 4"Much" 5"High level of support"
		lab val P3_1 trustortax2
		tab P3_1
		
		lab def taxtreat3 0"Trustee does not support" 1"Trustee support"
		lab val treatment_tax taxtreat3
		tab treatment_tax
		
		gen tax_support_dummy=P3_1
		recode tax_support_dummy 1=0 2=0 3=1 4=1 5=1

		psmatch2 tax_sup i.SEXO EDAD i.REG nat_pride author_personality mapuche_id P26_1 , n(3)
		reg Juego c.treatment_tax##c.P3_1 treatment_mapuche [iweight=_weight]
		

		margins, dydx(treatment_tax) at(P3_1=(1(1) 5)  )
		marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash))
		graph save Graph "tax support conditional effect.gph"

		

		
		**MODERATION of Trustor Mapuche identity (is Mapuche)
		*gen mapuche_id_dummy=1 if mapuche_id>2.5 & mapuche_id~=.
		*replace mapuche_id_dummy=0 if mapuche_id<2.6 & mapuche_id~=.
		tab mapuche_id
		lab def mapucheid1 1"Low level of Mapuche identification" 5"High level of Mapuche identification"
		lab val mapuche_id mapucheid1
		tab mapuche_id
		
		psmatch2  mapuche_id_dummy i.female EDAD i.REG nat_pride author_personality P26_1 , n(3)
		reg Juego  c.treatment_tax##c.mapuche_id treatment_mapuche [iweight=_weight]
					outreg2 using "RE Models Table", excel 


		margins, dydx(treatment_tax) at(mapuche_id=(1(1) 5)  )
		marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash))
		graph save Graph "mapuche id conditional effect.gph"
			
	
			***Ideology Identity
        tab P26_1
		lab def izder1 1"Left-wingers " 9"Right-wingers"
		lab val P26_1 izder1
		tab P26_1
		
		psmatch2 ideology_right_dummy  i.female EDAD i.REG nat_pride author_personality  mapuche_id, n(3) common
		reg Juego  c.treatment_tax##c.P26_1 treatment_mapuche [iweight=_weight]
			
		margins, dydx(treatment_tax) at(P26_1=(1(1) 9)  )
		marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash))
		graph save Graph "ideology conditional effect.gph"

		

		****Ideology and Identity
		pwcorr P26_1 P3_1 mapuche_id, sig

		xtreg Juego  c.treatment_tax##c.P26_1 c.treatment_tax##c.P3_1 treatment_mapuche , re

		xtreg Juego  c.treatment_tax##c.P26_1 c.treatment_tax##c.mapuche_id treatment_mapuche , re

	
		***descriptive stats

		sum  P3_1 mapuche_id P26_1 nat_pride author_personality  female EDAD     

		histogram Juego, scale(0.5) discrete fraction gap(20) scheme(s2mono) legend(off) ///
		by(, graphregion(fcolor(white) lcolor(white))) ///
		by(treatment_tax treatment_mapuche) note(off) ///
		title("") ///
		ytitle("Proportion") ///
		xtitle("Points Sent") ///
		xlabel(0(1)6)

				
		***random effects models***
		
		mixed Juego c.treatment_tax c.treatment_mapuche || numericalId:  c.treatment_tax c.treatment_mapuche
		outreg2 using "RE Models Table", excel replace
		mixed Juego c.treatment_tax##c.treatment_mapuche || numericalId:  c.treatment_tax c.treatment_mapuche
		outreg2 using "RE Models Table", excel 

		psmatch2 tax_sup i.SEXO EDAD i.REG nat_pride author_personality mapuche_id P26_1 , n(3)
		mixed  Juego c.treatment_tax##c.P3_1 treatment_mapuche|| numericalId:  c.treatment_tax c.treatment_mapuche [fweight=_weight]
				outreg2 using "RE Models Table", excel 

				reg Juego c.treatment_tax##c.P3_1 treatment_mapuche [iweight=_weight]
	
				margins, dydx(treatment_tax) at(P3_1=(1 5))  contrast
				
				
		psmatch2  mapuche_id_dummy i.female EDAD i.REG nat_pride author_personality P26_1 , n(3)
		mixed Juego  c.treatment_tax##c.mapuche_id treatment_mapuche || numericalId:  c.treatment_tax c.treatment_mapuche [fweight=_weight]  
				outreg2 using "RE Models Table", excel 

		reg Juego  c.treatment_tax##c.mapuche_id treatment_mapuche [iweight=_weight]  

		margins, dydx(treatment_tax) at(mapuche_id=(1 5))  contrast
				
		psmatch2 ideology_right_dummy  i.female EDAD i.REG nat_pride author_personality  mapuche_id, n(3) common
		mixed Juego  c.treatment_tax##c.P26_1 treatment_mapuche || numericalId:  c.treatment_tax c.treatment_mapuche [fweight=_weight]  
		outreg2 using "RE Models Table", excel 


		reg Juego  c.treatment_tax##c.P26_1  treatment_mapuche [iweight=_weight]  

		margins, dydx(treatment_tax) at(c.P26_1 =(1 9))  contrast
		
		
		
		
		***direct comparison of the treatment effects conditions by policy and ideology**
		
		xtreg Juego  c.treatment_tax##c.P26_1 c.treatment_tax##c.P3_1 treatment_mapuche , re
		
			margins, dydx(treatment_tax) at(  P3_1=(1 (1) 5)) vsquish
			
			marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")

			
margins, dydx(treatment_tax) at(  P26_1=(1 (1) 9)) vsquish

			marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")
				
		*** direct comparison of the treatment effects conditions by policy and mapuche id**
		
		xtreg Juego  c.treatment_tax##c.mapuche_id  c.treatment_tax##c.P3_1 treatment_mapuche , re
		
			margins, dydx(treatment_tax) at(  P3_1=(1 (1) 5)) vsquish
			
				marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")
			
					xtreg Juego  c.treatment_tax##c.mapuche_id  c.treatment_tax##c.P3_1 treatment_mapuche , re

margins, dydx(treatment_tax) at(  mapuche_id=(1 (1) 5)) vsquish

	marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")
		
		*** moderating effects without matching for SI***
				xtreg Juego c.treatment_tax##c.P3_1 treatment_mapuche, re
				
				
		margins, dydx(treatment_tax) at(P3_1=(1(1) 5)  )

			marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")		
					
	
		
				xtreg Juego  c.treatment_tax##c.mapuche_id treatment_mapuche, re
margins, dydx(treatment_tax) at(  mapuche_id=(1 (1) 5)) vsquish

			marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")
		
		
				xtreg Juego  c.treatment_tax##c.P26_1 treatment_mapuche , re
margins, dydx(treatment_tax) at(  P26_1=(1 (1) 9)) vsquish

			marginsplot, scheme(s2mono) graphregion(fcolor(white) lcolor(white)) yline(0) recast(line) recastci(rline) ciopts(lpattern(dash)) title("") ytitle("Treatment Effect of Pro-Tax Policy Treatment")
		
